import { Cell } from "@antv/x6";
/**
 * 启用辅助功能
 * @param { Element } elementGraph  --- 画布元素
 */
export const enableAuxiliaryFeatures = (elementGraph: any) => {
  const nodeList = elementGraph.getNodes().filter((item: Cell) => item.shape === "node-point");
  nodeList.forEach((item: Cell) => item.prop("isShowPortMagnet", true));
  elementGraph.toggleSelection(true);
  elementGraph.toggleHistory(true);
};
/**
 * 禁用辅助功能
 * @param { Element } elementGraph  --- 画布元素
 * @param { Element } containers - DOM元素
 */
export const disableAuxiliaryFeatures = (elementGraph: any, disable: boolean = true) => {
  if (disable) {
    elementGraph.toggleSelectionMovable(false);
    elementGraph.toggleSelection(false);
    elementGraph.cleanSelection();
    elementGraph.toggleHistory(false);
    stopDrawEdgeAndNode(elementGraph);
    elementGraph.off("node:mouseleave");
    elementGraph.off("node:mouseenter");
    elementGraph.off("edge:mouseleave");
    elementGraph.off("edge:mouseenter");
  }
};
/**
 * 事件停止
 * @param { Element }  elementGraph  --- 画布元素
 */
export const stopDrawEdgeAndNode = (elementGraph: any) => {
  elementGraph.off("blank:click");
  // elementGraph.off("blank:mousemove");
  elementGraph.off("blank:mouseup");
  elementGraph.off("blank:dblclick");
  elementGraph.off("blank:contextmenu");
  elementGraph.off("blank:mousewheel");
  elementGraph.off("graph:mouseleave");
  elementGraph.off("graph:mouseenter");
  // elementGraph.off("blank:mousedown");
  elementGraph.resetSelection();
};
